home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / uno.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-28  |  14.1 KB  |  386 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import sys
  6. sys.path.append('/usr/lib/openoffice/basis-link/program')
  7. if getattr(os.environ, 'URE_BOOTSTRAP', None) is None:
  8.     os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:/usr/lib/openoffice/program/fundamentalrc'
  9.  
  10. import pyuno
  11. import __builtin__
  12. import socket
  13. _g_ctx = pyuno.getComponentContext()
  14. _g_delegatee = __builtin__.__dict__['__import__']
  15.  
  16. def getComponentContext():
  17.     ''' returns the UNO component context, that was used to initialize the python runtime.
  18.     '''
  19.     return _g_ctx
  20.  
  21.  
  22. def getConstantByName(constant):
  23.     '''Looks up the value of a idl constant by giving its explicit name'''
  24.     return pyuno.getConstantByName(constant)
  25.  
  26.  
  27. def getTypeByName(typeName):
  28.     ''' returns a uno.Type instance of the type given by typeName. In case the
  29.         type does not exist, a com.sun.star.uno.RuntimeException is raised.
  30.     '''
  31.     return pyuno.getTypeByName(typeName)
  32.  
  33.  
  34. def createUnoStruct(typeName, *args):
  35.     '''creates a uno struct or exception given by typeName. The parameter args may
  36.     1) be empty. In this case, you get a default constructed uno structure.
  37.        ( e.g. createUnoStruct( "com.sun.star.uno.Exception" ) )
  38.     2) be a sequence with exactly one element, that contains an instance of typeName.
  39.        In this case, a copy constructed instance of typeName is returned
  40.        ( e.g. createUnoStruct( "com.sun.star.uno.Exception" , e ) )
  41.     3) be a sequence, where the length of the sequence must match the number of
  42.        elements within typeName (e.g.
  43.        createUnoStruct( "com.sun.star.uno.Exception", "foo error" , self) ). The
  44.        elements with in the sequence must match the type of each struct element,
  45.        otherwise an exception is thrown.
  46.     '''
  47.     return getClass(typeName)(*args)
  48.  
  49.  
  50. def getClass(typeName):
  51.     '''returns the class of a concrete uno exception, struct or interface
  52.     '''
  53.     return pyuno.getClass(typeName)
  54.  
  55.  
  56. def isInterface(obj):
  57.     '''returns true, when obj is a class of a uno interface'''
  58.     return pyuno.isInterface(obj)
  59.  
  60.  
  61. def generateUuid():
  62.     '''returns a 16 byte sequence containing a newly generated uuid or guid, see rtl/uuid.h '''
  63.     return pyuno.generateUuid()
  64.  
  65.  
  66. def systemPathToFileUrl(systemPath):
  67.     '''returns a file-url for the given system path'''
  68.     return pyuno.systemPathToFileUrl(systemPath)
  69.  
  70.  
  71. def fileUrlToSystemPath(url):
  72.     '''returns a system path (determined by the system, the python interpreter is running on)'''
  73.     return pyuno.fileUrlToSystemPath(url)
  74.  
  75.  
  76. def absolutize(path, relativeUrl):
  77.     '''returns an absolute file url from the given urls'''
  78.     return pyuno.absolutize(path, relativeUrl)
  79.  
  80.  
  81. def getCurrentContext():
  82.     '''Returns the currently valid current context.
  83.        see http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
  84.        for an explanation on the current context concept
  85.     '''
  86.     return pyuno.getCurrentContext()
  87.  
  88.  
  89. def setCurrentContext(newContext):
  90.     '''Sets newContext as new uno current context. The newContext must
  91.     implement the XCurrentContext interface. The implemenation should
  92.     handle the desired properties and delegate unknown properties to the
  93.     old context. Ensure to reset the old one when you leave your stack ...
  94.     see http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
  95.     '''
  96.     return pyuno.setCurrentContext(newContext)
  97.  
  98.  
  99. class Enum:
  100.     '''Represents a UNO idl enum, use an instance of this class to explicitly pass a boolean to UNO'''
  101.     
  102.     def __init__(self, typeName, value):
  103.         self.typeName = typeName
  104.         self.value = value
  105.         pyuno.checkEnum(self)
  106.  
  107.     
  108.     def __repr__(self):
  109.         return '<uno.Enum %s (%r)>' % (self.typeName, self.value)
  110.  
  111.     
  112.     def __eq__(self, that):
  113.         if not isinstance(that, Enum):
  114.             return False
  115.         if self.typeName == that.typeName:
  116.             pass
  117.         return self.value == that.value
  118.  
  119.  
  120.  
  121. class Type:
  122.     '''Represents a UNO type, use an instance of this class to explicitly pass a boolean to UNO'''
  123.     
  124.     def __init__(self, typeName, typeClass):
  125.         self.typeName = typeName
  126.         self.typeClass = typeClass
  127.         pyuno.checkType(self)
  128.  
  129.     
  130.     def __repr__(self):
  131.         return '<Type instance %s (%r)>' % (self.typeName, self.typeClass)
  132.  
  133.     
  134.     def __eq__(self, that):
  135.         if not isinstance(that, Type):
  136.             return False
  137.         if self.typeClass == that.typeClass:
  138.             pass
  139.         return self.typeName == that.typeName
  140.  
  141.     
  142.     def __hash__(self):
  143.         return self.typeName.__hash__()
  144.  
  145.  
  146.  
  147. class Bool(object):
  148.     """Represents a UNO boolean, use an instance of this class to explicitly 
  149.        pass a boolean to UNO.
  150.        Note: This class is deprecated. Use python's True and False directly instead
  151.     """
  152.     
  153.     def __new__(cls, value):
  154.         if isinstance(value, (str, unicode)) and value == 'true':
  155.             return True
  156.         if isinstance(value, (str, unicode)) and value == 'false':
  157.             return False
  158.         if value:
  159.             return True
  160.         return False
  161.  
  162.  
  163.  
  164. class Char:
  165.     '''Represents a UNO char, use an instance of this class to explicitly pass a char to UNO'''
  166.     
  167.     def __init__(self, value):
  168.         if not isinstance(value, unicode):
  169.             raise AssertionError
  170.         if not len(value) == 1:
  171.             raise AssertionError
  172.         self.value = value
  173.  
  174.     
  175.     def __repr__(self):
  176.         return '<Char instance %s>' % (self.value,)
  177.  
  178.     
  179.     def __eq__(self, that):
  180.         if isinstance(that, (str, unicode)):
  181.             if len(that) > 1:
  182.                 return False
  183.             return self.value == that[0]
  184.         if isinstance(that, Char):
  185.             return self.value == that.value
  186.         return False
  187.  
  188.  
  189.  
  190. class ByteSequence:
  191.     
  192.     def __init__(self, value):
  193.         if isinstance(value, str):
  194.             self.value = value
  195.         elif isinstance(value, ByteSequence):
  196.             self.value = value.value
  197.         else:
  198.             raise TypeError('expected string or bytesequence')
  199.         return isinstance(value, str)
  200.  
  201.     
  202.     def __repr__(self):
  203.         return "<ByteSequence instance '%s'>" % (self.value,)
  204.  
  205.     
  206.     def __eq__(self, that):
  207.         if isinstance(that, ByteSequence):
  208.             return self.value == that.value
  209.         if isinstance(that, str):
  210.             return self.value == that
  211.         return False
  212.  
  213.     
  214.     def __len__(self):
  215.         return len(self.value)
  216.  
  217.     
  218.     def __getitem__(self, index):
  219.         return self.value[index]
  220.  
  221.     
  222.     def __iter__(self):
  223.         return self.value.__iter__()
  224.  
  225.     
  226.     def __add__(self, b):
  227.         if isinstance(b, str):
  228.             return ByteSequence(self.value + b)
  229.         if isinstance(b, ByteSequence):
  230.             return ByteSequence(self.value + b.value)
  231.         raise TypeError('expected string or ByteSequence as operand')
  232.  
  233.     
  234.     def __hash__(self):
  235.         return self.value.hash()
  236.  
  237.  
  238.  
  239. class Any:
  240.     '''use only in connection with uno.invoke() to pass an explicit typed any'''
  241.     
  242.     def __init__(self, type, value):
  243.         if isinstance(type, Type):
  244.             self.type = type
  245.         else:
  246.             self.type = getTypeByName(type)
  247.         self.value = value
  248.  
  249.  
  250.  
  251. def invoke(object, methodname, argTuple):
  252.     '''use this function to pass exactly typed anys to the callee (using uno.Any)'''
  253.     return pyuno.invoke(object, methodname, argTuple)
  254.  
  255.  
  256. def _uno_import(name, *optargs, **kwargs):
  257.     
  258.     try:
  259.         return _g_delegatee(name, *optargs, **kwargs)
  260.     except ImportError:
  261.         (globals, locals, fromlist) = list(optargs)[:3] + [
  262.             kwargs.get('globals', { }),
  263.             kwargs.get('locals', { }),
  264.             kwargs.get('fromlist', [])][len(optargs):]
  265.         if not fromlist:
  266.             raise 
  267.         fromlist
  268.  
  269.     modnames = name.split('.')
  270.     mod = None
  271.     d = sys.modules
  272.     for x in modnames:
  273.         if d.has_key(x):
  274.             mod = d[x]
  275.         else:
  276.             mod = pyuno.__class__(x)
  277.         d = mod.__dict__
  278.     
  279.     RuntimeException = pyuno.getClass('com.sun.star.uno.RuntimeException')
  280.     for x in fromlist:
  281.         if not d.has_key(x):
  282.             if x.startswith('typeOf'):
  283.                 
  284.                 try:
  285.                     d[x] = pyuno.getTypeByName(name + '.' + x[6:len(x)])
  286.                 except RuntimeException:
  287.                     e = None
  288.                     raise ImportError('type ' + name + '.' + x[6:len(x)] + ' is unknown')
  289.                 except:
  290.                     None<EXCEPTION MATCH>RuntimeException
  291.                 
  292.  
  293.             None<EXCEPTION MATCH>RuntimeException
  294.             
  295.             try:
  296.                 d[x] = pyuno.getClass(name + '.' + x)
  297.             except RuntimeException:
  298.                 e = None
  299.                 
  300.                 try:
  301.                     d[x] = Enum(name, x)
  302.                 except RuntimeException:
  303.                     e2 = None
  304.                     
  305.                     try:
  306.                         d[x] = getConstantByName(name + '.' + x)
  307.                     except RuntimeException:
  308.                         e3 = None
  309.                         raise ImportError('type ' + name + '.' + x + ' is unknown')
  310.                     except:
  311.                         None<EXCEPTION MATCH>RuntimeException
  312.                     
  313.  
  314.                     None<EXCEPTION MATCH>RuntimeException
  315.                 
  316.  
  317.                 None<EXCEPTION MATCH>RuntimeException
  318.             
  319.  
  320.         None<EXCEPTION MATCH>RuntimeException
  321.     
  322.     return mod
  323.  
  324. __builtin__.__dict__['__import__'] = _uno_import
  325.  
  326. def _impl_extractName(name):
  327.     r = range(len(name) - 1, 0, -1)
  328.     for i in r:
  329.         if name[i] == '.':
  330.             name = name[i + 1:len(name)]
  331.             break
  332.             continue
  333.     
  334.     return name
  335.  
  336.  
  337. def _uno_struct__init__(self, *args):
  338.     if len(args) == 1 and hasattr(args[0], '__class__') and args[0].__class__ == self.__class__:
  339.         self.__dict__['value'] = args[0]
  340.     else:
  341.         self.__dict__['value'] = pyuno._createUnoStructHelper(self.__class__.__pyunostruct__, args)
  342.  
  343.  
  344. def _uno_struct__getattr__(self, name):
  345.     return __builtin__.getattr(self.__dict__['value'], name)
  346.  
  347.  
  348. def _uno_struct__setattr__(self, name, value):
  349.     return __builtin__.setattr(self.__dict__['value'], name, value)
  350.  
  351.  
  352. def _uno_struct__repr__(self):
  353.     return repr(self.__dict__['value'])
  354.  
  355.  
  356. def _uno_struct__str__(self):
  357.     return str(self.__dict__['value'])
  358.  
  359.  
  360. def _uno_struct__eq__(self, cmp):
  361.     if hasattr(cmp, 'value'):
  362.         return self.__dict__['value'] == cmp.__dict__['value']
  363.     return False
  364.  
  365.  
  366. def _uno_extract_printable_stacktrace(trace):
  367.     mod = None
  368.     
  369.     try:
  370.         mod = __import__('traceback')
  371.     except ImportError:
  372.         e = None
  373.  
  374.     ret = ''
  375.     if mod:
  376.         lst = mod.extract_tb(trace)
  377.         max = len(lst)
  378.         for j in range(max):
  379.             i = lst[max - j - 1]
  380.             ret = ret + '  ' + str(i[0]) + ':' + str(i[1]) + ' in function ' + str(i[2]) + '() [' + str(i[3]) + ']\n'
  381.         
  382.     else:
  383.         ret = "Couldn't import traceback module"
  384.     return ret
  385.  
  386.